/*
 * 文件名：ArticleController.java	 
 * 时     间：上午11:32:38
 * 作     者：liyf      
 * 版     权： 2014-2022  智慧园区, 公司保留所有权利.
 * 联     系：www.szyungu.com
 */
package com.qianhai.news.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.qianhai.common.constants.CommonContans;
import com.qianhai.common.controller.BaseController;
import com.qianhai.news.model.Article;
import com.qianhai.news.model.ArticleExample;
import com.qianhai.news.service.face.ArticleService;

/**
 * @ClassName: ArticleController
 * @Description: 统一文章管理,包括文件类型、文章
 * @author liyf
 * @date 2014年11月14日 上午11:32:38
 */
@RestController
@RequestMapping(value = "/index/article", method = RequestMethod.POST)
public class IndexArticleManagerController extends BaseController
{
	@Autowired
	private ArticleService articleService;

	

	


	
	
	/**
	 * 
	 * @方法名称: queryArticleByKey
	 * @描述: 通过关键字查询
	 *
	 * @参数:
	 * @param uuid
	 * @return
	 *
	 * @返回类型: ModelMap
	 * @作者:liyf
	 * @可能抛出异常:
	 */
	@RequestMapping(value = "/queryArticleByKey.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryArticleByKey(String uuid)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			Article article = articleService.selectByPrimaryKey(uuid);
			
			resultMap.put(CommonContans.STRUTS_DATA, article);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	/**
	 * 
	 * @方法名称: queryArticleByCode 
	 * @描述: 
	 *     根据文章code跟语言类型来查找到唯一的文章
	 *
	 * @参数:
	 *    @param code
	 *    @param language
	 *    @return
	 *
	 * @返回类型: ModelMap
	 * @作者:chenyi
	 * @可能抛出异常:
	 */
	@RequestMapping(value = "/queryArticleByCode.action", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryArticleByCode(String code,String language)
	{
		ModelMap resultMap = new ModelMap();
		
		try
		{
			ArticleExample ae = new ArticleExample();
			ae.or().andArticleCodeEqualTo(code).andArticleLanguageEqualTo(language);
			List<Article> list = articleService.selectByCondition(ae);
			
			Article article = new Article();
			if(list!=null && list.size()>0){
				article = list.get(0);
			}
			
			resultMap.put(CommonContans.STRUTS_DATA, article);
			resultMap.put(CommonContans.STRUTS_RESULT,
					CommonContans.STRUTS_SUCCESS);
		} catch (Throwable e)
		{
			// 请保持所有代码一直性，没有特殊处理请使用该代码.
			this.printExction(resultMap, e);
		}
		return resultMap;
	}
	
	
}
